package edu.rit.drh4818.fire.data;


/**
 * Data is taken from the surrounding scene.
 * 
 * @author Darren Headrick
 *
 */
public class SexyData extends EmitterVolume
{
	public static String NAME = "2D Sexy";
	private static final int DIMENSION = 50;
	private static final float factor = 39F/330F;
	
	public SexyData()
	{
		super( DIMENSION, true, NAME );
	}
	
	/*
	 * (non-Javadoc)
	 * @see edu.rit.drh4818.volume.renderer.VolData#update()
	 */
	public void update() 
	{
		if( volData == null ) return;
		
		super.update();
		
		for(int z = 0; z < DIMENSION; z++ )
		for(int y = DIMENSION-1; y >= 0 ; y--)
	    for(int x = 0; x < DIMENSION; x++)
	    {
	       volData[x][y][z] = (short)((
	  	         volData[x % DIMENSION][(y - 1 + DIMENSION) % DIMENSION][z]                                                  
	  	         + volData[x % DIMENSION][(y - 2 + DIMENSION) % DIMENSION][z]
	  	         + volData[x % DIMENSION][(y - 3 + DIMENSION) % DIMENSION][z]
                 + volData[x % DIMENSION][(y - 1 + DIMENSION) % DIMENSION][z]
                 + volData[(x - 1 + DIMENSION) % DIMENSION][(y - 1+DIMENSION) % DIMENSION][z]
	  	         + volData[(x + 1) % DIMENSION][(y - 1+DIMENSION) % DIMENSION][z]
	  	         + volData[x][(y - 1 + DIMENSION) % DIMENSION][(z - 1+ DIMENSION) % DIMENSION]
	  	         + volData[x][(y - 1 + DIMENSION) % DIMENSION][(z + 1) % DIMENSION]
	  	         ) * factor);
	    }

		generateTexture();
	}

	/**
	 * Change the direction of the dataset.
	 */
	public short get( int x, int y, int z )
    {
		if( volData == null ) return 0;
		
		if( volData[x][y][z] > 255 ) return 0;
		return (short)(255 - volData[x][y][z]*6); 
//		short val = (short)(255 - volData[x][y][z]); 
//    	if( val == 255 ) return 255;
//		return (short)(val / 2);
    }
}
